using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;


namespace VI.Chat.VIChatControl
{
    public class ChatController : Controller
    {
        //
        // GET: /Chat/

        public JsonResult Index()
        {

            return null;
        }
        //Active User Action
        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult ActivateUser(string user)
        {
            ChatManager cm = new ChatManager();
            cm.ActivateUser(user);
            return Json(true);
        }

        //Deactive User Action
        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult DeactivateUser(string user)
        {
            ChatManager cm = new ChatManager();
            if(cm.CurrentSession.User != null)
                cm.DeactivateUser(cm.CurrentSession.User);
            else
                cm.DeactivateUser(user);
            return Json(true);
        }

        //Get Active User list
        public JsonResult GetActiveUsers()
        {
            ChatManager cm = new ChatManager();
            return this.Json(cm.ActiveUserList);
        }
        //Send a message
        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult SendMessage(string toUser, string message)
        {
            ChatManager cm = new ChatManager();
            cm.SendMessage(toUser, message);
            return Json(true);
        }

        //Get message list
        public JsonResult CheckMessages()
        {
            ChatManager cm = new ChatManager();

            return this.Json(cm.GetMessages());
        }

    }
}
